import re
import os
import my_function as my
# holy sites
with open(r'ck3/game_path.txt', 'r', encoding='utf-8') as file:
    game_path = file.read()  # 读取全部内容到一个字符串

# invite courts
# file_path = game_path + "/game/common/activities/activity_types/pilgrimage.txt"
# with open(file_path, 'r', encoding='utf-8') as file:
#     content = file.read()
# regular_pattern = 'gold >= .*'
# new_pattern = 'gold >= 0'
# content = re.sub(regular_pattern, new_pattern, content)
# with open(file_path, 'w', encoding='utf-8') as file:
#     file.write(content)

# contract
file_path = game_path + "/game/common/character_interactions/00_modifiy_vassal_contract.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = 'subject_contract_is_blocked_from_modification'
new_pattern = '#subject_contract_is_blocked_from_modification'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

# era
# file_path = game_path + "/game/common/culture/eras/00_culture_eras.txt"
# with open(file_path, 'r', encoding='utf-8') as file:
#     content = file.read()
# regular_pattern = r'year = .*'
# new_pattern = r'year = 9999'
# content = re.sub(regular_pattern, new_pattern, content)
# with open(file_path, 'w', encoding='utf-8') as file:
#     file.write(content)

# block_head = "culture_era_tribal"
# file_path = game_path + "/game/common/culture/eras/00_culture_eras.txt"
# new_block_content = block_head + """ = {
#     year = 0
# }"""
# my.replace_block(file_path, block_head, new_block_content)

## ai
file_path = game_path + "/game/common/defines/ai/00_ai.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
# regular_pattern = r'AI_BASE_WAR_CHANCE = .*'
# new_pattern = r'AI_BASE_WAR_CHANCE = 10000'
# content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'RETREAT_COMBAT_PREDICTION_RATIO = .*'
new_pattern = r'RETREAT_COMBAT_PREDICTION_RATIO = 0'
content = re.sub(regular_pattern, new_pattern, content)
# regular_pattern = r'RETREAT_TO_BETTER_TERRAIN_DISTANCE = .*'
# new_pattern = r'RETREAT_TO_BETTER_TERRAIN_DISTANCE = 0'
# content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'RETREAT_IF_MISSING_STRENGTH = .*'
new_pattern = r'RETREAT_IF_MISSING_STRENGTH = 0.1'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

# seduce and court
file_path = game_path + r"/game/common/schemes/scheme_types/court_scheme.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = 'base_progress_goal =.*'
new_pattern = 'base_progress_goal = 10'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)
regular_pattern = 'minimum_success =.*'
new_pattern = 'minimum_success = 100'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

file_path = game_path + r"/game/common/schemes/scheme_types/seduce_scheme.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = 'base_progress_goal =.*'
new_pattern = 'base_progress_goal = 10'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)
regular_pattern = 'minimum_success =.*'
new_pattern = 'minimum_success = 100'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

## buy claims
# file_path = game_path + r"/game/common/character_interactions/00_perk_interactions.txt"
# with open(file_path, 'r', encoding='utf-8') as file:
#     content = file.read()
# regular_pattern = r'target_is_liege_or_above = scope:actor'
# new_pattern = r'#target_is_liege_or_above = scope:actor'
# content = re.sub(regular_pattern, new_pattern, content)
# regular_pattern = r'has_perk = sanctioned_loopholes_perk'
# new_pattern = r'is_close_or_extended_family_of = root'
# content = re.sub(regular_pattern, new_pattern, content)
# with open(file_path, 'w', encoding='utf-8') as file:
#     file.write(content)


# war
file_path = game_path + r"/game/common/character_interactions/00_war.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'has_raised_armies'
new_pattern = r'#has_raised_armies'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

# war score
folder_path = game_path + r"/game/common/casus_belli_types"
for filename in os.listdir(folder_path):
    file_path = os.path.join(folder_path, filename)
    if os.path.isfile(file_path):  # 确保是文件而非文件夹
        with open(file_path, 'r', encoding='utf-8') as file:
            content = file.read()
        regular_pattern = 'max_attacker_score_from_battles =.*'
        new_pattern = 'max_attacker_score_from_battles = 1000'
        content = re.sub(regular_pattern, new_pattern, content)
        regular_pattern = 'max_defender_score_from_battles =.*'
        new_pattern = 'max_defender_score_from_battles = 1000'
        content = re.sub(regular_pattern, new_pattern, content)
        with open(file_path, 'w', encoding='utf-8') as file:
            file.write(content)